package com.ruoyi.project.device.curing.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.project.device.curing.domain.BasDeviceCuring;
import com.ruoyi.project.device.curing.service.IBasDeviceCuringService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 保养记录Controller
 * 
 * @author wld
 * @date 2023-04-04
 */
@Controller
@RequestMapping("/device/curing")
public class BasDeviceCuringController extends BaseController
{
    private String prefix = "device/curing";

    @Autowired
    private IBasDeviceCuringService basDeviceCuringService;

    @GetMapping()
    public String curing()
    {
        return prefix + "/curing";
    }

    /**
     * 查询保养记录列表
     */
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(BasDeviceCuring basDeviceCuring)
    {
        startPage();
        List<BasDeviceCuring> list = basDeviceCuringService.selectBasDeviceCuringList(basDeviceCuring);
        return getDataTable(list);
    }

    /**
     * 导出保养记录列表
     */
    @Log(title = "保养记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(BasDeviceCuring basDeviceCuring)
    {
        List<BasDeviceCuring> list = basDeviceCuringService.selectBasDeviceCuringList(basDeviceCuring);
        ExcelUtil<BasDeviceCuring> util = new ExcelUtil<BasDeviceCuring>(BasDeviceCuring.class);
        return util.exportExcel(list, "保养记录数据");
    }

    /**
     * 新增保养记录
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存保养记录
     */
    @Log(title = "保养记录", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(BasDeviceCuring basDeviceCuring)
    {
        return toAjax(basDeviceCuringService.insertBasDeviceCuring(basDeviceCuring));
    }

    /**
     * 修改保养记录
     */
    @GetMapping("/edit/{deviceId}")
    public String edit(@PathVariable("deviceId") String deviceId, ModelMap mmap)
    {
        BasDeviceCuring basDeviceCuring = basDeviceCuringService.selectBasDeviceCuringByDeviceId(deviceId);
        mmap.put("basDeviceCuring", basDeviceCuring);
        return prefix + "/edit";
    }

    /**
     * 修改保存保养记录
     */
    @Log(title = "保养记录", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(BasDeviceCuring basDeviceCuring)
    {
        return toAjax(basDeviceCuringService.updateBasDeviceCuring(basDeviceCuring));
    }

    /**
     * 删除保养记录
     */
    @Log(title = "保养记录", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(basDeviceCuringService.deleteBasDeviceCuringByDeviceIds(ids));
    }
}
